package com.lingeringdream.luciole.helper.album;

import com.zhihu.matisse.MimeType;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.fraction.Fraction;

import java.lang.ref.WeakReference;
import java.util.Set;

/**
 * 相册helper
 *
 * @author Kirky-X
 */
public class AlbumHelper {
    private final WeakReference<Ability> mContext;
    private final WeakReference<Fraction> mFraction;
    private final WeakReference<AbilitySlice> mAbilitySlice;

    private AlbumHelper(Ability ability, Fraction fraction, AbilitySlice abilitySlice) {
        this.mContext = new WeakReference(ability);
        this.mFraction = new WeakReference(fraction);
        this.mAbilitySlice = new WeakReference(abilitySlice);
    }

    private AlbumHelper(Ability ability) {
        this(ability, null, null);
    }

    private AlbumHelper(Fraction fraction) {
        this(fraction.getFractionAbility(), fraction, null);
    }

    private AlbumHelper(AbilitySlice abilitySlice) {
        this(abilitySlice.getAbility(), null, abilitySlice);
    }

    public static AlbumHelper from(Ability ability) {
        return new AlbumHelper(ability);
    }

    public static AlbumHelper from(Fraction fraction) {
        return new AlbumHelper(fraction);
    }

    public static AlbumHelper from(AbilitySlice abilitySlice) {
        return new AlbumHelper(abilitySlice);
    }

    public SelectionCreator choose(Set<MimeType> set) {
        return this.choose(set, true);
    }

    public SelectionCreator choose(Set<MimeType> set, boolean exclusiveType) {
        return new SelectionCreator(this, set, exclusiveType);
    }

    Ability getAbility() {
        return this.mContext.get();
    }

    Fraction getFraction() {
        return this.mFraction != null ? this.mFraction.get() : null;
    }

    AbilitySlice getAbilitySlice() {
        return this.mAbilitySlice != null ? this.mAbilitySlice.get() : null;
    }
}
